/**
 * 
 */
package com.jiang.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import com.jiang.dao.IProvinceDao;
import com.jiang.vo.Area;
import com.jiang.vo.AreaPlus;

/**
 * @author Administrator
 *
 */
public class ProvinceDaoImpl implements IProvinceDao {

	private Connection conn;
	private PreparedStatement ps;
	
	public ProvinceDaoImpl(Connection conn) {
		this.conn = conn;
	}
	
	@Override
	public boolean doCreate(Area vo) throws Exception {
		return false;
	}

	@Override
	public boolean doUpdate(Area vo) throws Exception {
		return false;
	}

	@Override
	public boolean doRemoveBatch(Set<Integer> ids) throws Exception {
		return false;
	}

	@Override
	public Area findById(Integer id) throws Exception {
		return null;
	}

	/* (non-Javadoc)
	 * @see com.jiang.dao.IDAO#findAll()
	 */
	@Override
	public List<Area> findAll() throws Exception {
		List<Area> areas = new ArrayList<Area>();
		// 查询出所有的省份
		StringBuffer sb = new StringBuffer();
		sb.append(" SELECT aid,title FROM area ");
		ps = conn.prepareStatement(sb.toString());
		ResultSet rs = ps.executeQuery();
		while(rs.next()){
			Area area = new Area();
			area.setAid(rs.getInt(1));
			area.setTitle(rs.getString(2));
			areas.add(area);
		}
		return areas;
	}

	/* (non-Javadoc)
	 * @see com.jiang.dao.IDAO#findAllSplit(java.lang.Integer, java.lang.Integer, java.lang.String, java.lang.String)
	 */
	@Override
	public List<Area> findAllSplit(Integer currentPage, Integer lineSize, String column, String keyWord)
			throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see com.jiang.dao.IDAO#getAllCount(java.lang.String, java.lang.String)
	 */
	@Override
	public Integer getAllCount(String column, String keyWord) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<AreaPlus> findCitiesByAreaId(Integer id) throws Exception{
		List<AreaPlus> areapluses = new ArrayList<AreaPlus>();
		// 查询出所有的省份
		StringBuffer sb = new StringBuffer();
		sb.append(" SELECT apid,aid,title FROM areaplus WHERE aid = ?");
		ps = conn.prepareStatement(sb.toString());
		ps.setInt(1, id);
		ResultSet rs = ps.executeQuery();
		while(rs.next()){
			AreaPlus areaplus = new AreaPlus();
			areaplus.setApid(rs.getInt(1));
			areaplus.setAid(rs.getInt(2));
			areaplus.setTitle(rs.getString(3));
			areapluses.add(areaplus);
		}
		return areapluses;
	}

}
